<?php
require_once("includes/pagetop.php");
include_once("updates/CommonFeatures.php");
include_once("includes/common_snippets.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}

$logObj=new Log();

$noofappsloadpermoreclick=1;
$noofsponcersdefault=5;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>AllyFolio | Page </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />
<script src="js/general.js"></script>
<script src="js/functions.js"></script>

<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>

	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<?php include_once "includes/header.php"; ?>
    <!--=================Header end=======================-->
    
    
    <script type="text/javascript">
    $(function() { $('input, textarea').placeholder();});
</script>

<style type="text/css">

    .chat_box{

        display:none;

    }

    .placeholder {

      color: #cccccc;

      }
/* emotions */
#emotionsdrp{
    position: absolute;
    padding: 4px;
}

#emotionsdrp div .em{
    cursor: pointer;
    padding: 2px;
} 
#emotionsdrp{
    background-color: gainsboro;
    width: 130px;
}
.em{
    
}
.em:hover{
    background-color: cadetblue;
    cursor:pointer;
}
</style>

<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	

	}

	.new tr td{ vertical-align:top}

	

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

    

    /* added by sujeet */

    .privacy-drp-menu{

        border:1px solid blue;

        display: none;

    }

    .privacy-drp-menu-items{

        border-bottom: 1px solid gray;

        cursor:pointer;

    }

    .comment{

        width: 82%;

        height: 25px;

        padding-left: 4px;

        padding-right: 4px;

        border:none; 

        background:none;

    }   

    .listenMe{

        width: 100%;

        text-align: center;

        padding-top: 14px;

        padding-bottom: 14px;

    }

    .feed{

        margin-top: 20px;

    }

</style>


<!-- custom post submission jquery by sujeet -->
<?php include_once("smiley.php");?>
<script type="text/javascript" src="js/smiley.js"></script>
<script src="js/autoloading.js"></script>
<script src="js/custom_popupshow.js"></script>
<script src="js/jquery.asyncpost.js"></script>
<script type="text/javascript" src="js/jwplayer.js"></script>
</head>

<body>
<?php
include_once("updates/ReadNotifications.php");
try{
    $loggedUserObj=new UserDetails();
    
    if (!isset($_SESSION["User_details"])){
        $_SESSION["User_details"]=$loggedUserObj->getUserDetails($_SESSION["Allyfolio_User_ID"],true);
    }
    $loggedUserObj=$_SESSION["User_details"];
    $loggedUserObj->latestFriendNotificationsArr=array(1=>"sumer",2=>"vikas");            
    //echo "<pre>";
//    print_r($loggedUserObj);
//    echo "</pre>";

}
catch(Exception $ex){
    $logObj->writeException("home.php Exception: => ".$ex->getMessage());
    die("Home.php fetching user details".$ex->getMessage());
}
 
//data from user config
$userSettings=array(
                'emailid'=>$loggedUserObj->emailId,
                'id'=>$_SESSION["Allyfolio_User_ID"],
                'privacy_settings'=>$loggedUserObj->privacyType["Default_Setting"]
                );
                
$_SESSION['user_settings']=$userSettings;
//print_r($_SESSION['user_settings']);

include_once "page_common.php";

//Join/leave this Page
if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']!=0 && isset($_REQUEST["action"])  )
{
	if($_REQUEST["action"]=="join")
	{
		if($isPageOwner)
		{
			$msg_error="You can join your own page.";
		}
		else if($isPageMember)
		{
			$msg_error="You have already joined this page.";
		}
		else
		{
			$insertqry="insert into af_company_page_members set comp_page_id=:comp_page_id, user_id=:user_id, join_date='".time()."'";
			$pdodbobj->query($insertqry,array(":comp_page_id"=>$arrPageDetail[0]["Comp_Page_ID"],":user_id"=>$_SESSION['Allyfolio_User_ID']));
			$isPageMember=true;
			$msg_success="You have joined this page.";
		}
	}
	else if($_REQUEST["action"]=="leave")
	{
		if(!$isPageMember)
		{
			$msg_error="You are not member of this page.";
		}
		else
		{
			$qryDelete="delete from af_company_page_members where comp_page_id=:comp_page_id and user_id=:user_id";
			$pdodbobj->query($qryDelete,array(":comp_page_id"=>$arrPageDetail[0]["Comp_Page_ID"],":user_id"=>$_SESSION['Allyfolio_User_ID']));
			$isPageMember=false;
			$msg_success="You have left this page.";
		}
	}
}

?>
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
    	<?php include_once("page_top.php") ?>
      <div class="header">
        <div class="contain-wrap2 shadow" style="margin-top:30px; width:100%; ">
          
        <div class="home_left">
            <?php include_once("home_leftsidebar.php"); ?>
		</div>
		<div class="home_right">
		<table width="100%" border="0">

			<tr>

				<td> 
                    <div id="stupdthandler"></div>
                    <div id="light_stupdtsec">
                    <form id="frmstupdt" name="frmstupdt" action="ajax/update_data.php?action=st_update" enctype="multipart/form-data" > 
						<input type="hidden" id="nPostType" name="nPostType" value="5" />
						<input type="hidden" id="Post[Parent_ID]" name="Post[Parent_ID]" value="<?php echo $arrPageDetail[0]["Comp_Page_ID"]; ?>" />
					<div class="status">

						<div class="status_top">
							
                            <?php

                            $oDropfilters= new CGetFilters();

                            $privacyTypes=$oDropfilters->getFilters("privacy_types");

                            //print_r($privacyTypes);

                            ?>

                            <div id="statusshare">

                                <input type="text" id="ajx_status_update" name="ajx_status_update" placeholder="Enter your text here.." />
								<input type="hidden" id="nPostType" name="nPostType" value="5" />
							<input type="hidden" id="Post[Parent_ID]" name="Post[Parent_ID]" value="<?php echo $arrPageDetail[0]["Comp_Page_ID"]; ?>" />
                                <div id="status_tagging" style="display: none;">

                                    <div style="border-top: dashed 1px gray;">

                                        <input type="text" id="st_taggedusers" name="st_taggedusers" placeholder="Enter friends name.." />

                                        <input type="hidden" id="sttaggedusers" name="sttaggedusers" />

                                    </div>

                                    

                                </div>
                                
                                <div id="status_emotions" style="display: none;">
                                    <div style="border-top: dashed 1px gray;">
                                    <!--
                                        <div id="st_emotionsfeeling_txt" style="display: none;">
                                            <input type="text" id="st_emotionsfeeling" name="st_emotionsfeeling" placeholder="what you do.." onclick="return openEmotionCategoriesList();"/>
                                        </div>
                                        -->
                                        <div id="st_emotionsfeeling_div" onclick="return openEmotionCategoriesList();" style="height:25px"></div>
                                        <input type="hidden" id="stemotionsfeeling" name="stemotionsfeeling" />
                                    </div>
                                    <div id="emotionslist" style="width: 150px;position: absolute;display:none"></div>
                                    

                                </div>

                            </div>

							

								<div class="stat_bot">

                                    <div>

                                        <span id="post_location" style="padding: 5px;"></span>

                                    </div>

                                    <div id="image_loader_div" style="display:none;"><img src="images/LoadingBar.gif" width="64px" height="64px"/></div>

                                    <div id="post_media_thumb_div">

                                        

                                    </div>

                                    <br />

									<ul>

										<li >

                                            <select id="prvset" id="prvset" onchange="setPrivacySetting(this.value)">

                                                <?php

                                                 $myprivacysetting=0;

                                                if (!empty($_SESSION['user_settings']['privacy_settings'])) {

                                                    $myprivacysetting = trim($_SESSION['user_settings']['privacy_settings']);

                                                }

                                                if(is_numeric($myprivacysetting) && $myprivacysetting>0){

                                                    $defaultSelected=$myprivacysetting;

                                                }

                                                else{

                                                    $defaultSelected=1; //privacy type assigned    

                                                }

                                                foreach($privacyTypes as $privacyType){

                                                    if($privacyType["ID"]==$defaultSelected){

                                                        $selected=true;

                                                    }

                                                    else if($privacyType["keyword"]=="public"){

                                                        $selected=true;

                                                    }

                                                    else{

                                                        $selected=false;

                                                    }

                                                        

                                                        

                                                    ?>

                                                    <option value="<?php echo $privacyType["ID"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >

                                                        <?php echo $privacyType["Privacy_Type_Title"]; ?> 

                                                    </option>

                                                    <?php

                                                }

                                                ?>

                                            </select>
                                            <div id="st_myclusters" style="display:none">
                                                <select id="st_share_with_cluster" name="st_share_with_cluster">                                                    
                                                </select>
                                            </div>
        
        
                                        </li>

										<li>

											<a href="javascript:void(0)" onclick="return openFile('status_update_file')"><img src="images/ico/5.png" /></a>

											<div id="image_loader_div" style="display:none;"><img src="images/LoadingBar.gif" width="64px" height="64px"/></div>

											<input type="file" id="status_update_file" name="status_update_file" style="display:none;" accept="audio/*,video/*,image/*" onchange="return uploadMedia('1','status_update_file','frmstupdt','post_media_thumb_div','status_file_hidden');" />

											<input type="hidden" name="status_file_hidden" id="status_file_hidden" value="" />

											<!-- 1 for status Update -->

										</li>

										<li>

											<a href="javascript:void(0)" onclick="return openFile('status_update_file')"><img src="images/ico/6.png" /></a>

										</li>

										<li>
                                            <a href="javascript:void(0)" onclick="return showEmotionsBox();">
                                                <img src="images/ico/7.png" />
                                            </a>
                                        </li>

										<li>

                                            <a href="javascript:void(0)" onclick="showAddLocationBox();" title="Add Location">

                                                <img src="images/ico/8.png" />

                                            </a>

                                        </li>

										<li>

                                            <a href="javascript:void(0)" onclick="showStatusTaggedBox();" title="Add Location">

                                                <img src="images/ico/9.png" />

                                            </a>

                                        </li>

										<li style="float:right;">

                                            <a href="add_blog.php">

                                                <!--<span style="padding-right:5px;">Create Blog</span>-->    
                                                <input type="button"  style="width:100px!important" value="Create Blog" />
                                            </a>

											<input type="button" id="#post_s" style="width:80px!important;cursor: pointer;" onclick="updateStatus('frmstupdt');" value="send" />

											<!--

	                                        <span id="#post_s" onclick="updateStatus('frmstupdt');">send</span>

	                                        -->

                                        </li>

									</ul>

									<div class="clearfix"></div>

                                    <input type="hidden" id="locstr" name="locstr" value="NONE" />

							</div>

						</div>

					</div>

                    <div id="errconsole"></div>

                    </form>
                </div>
				</td>

				<td width="15%" style="vertical-align:top;">
					<?php include_once "page_right_links.php"; ?>
				</td>
				<td></td>

			</tr>

		</table>
        
        <style>
        #tweets { }
        #overlay { position: absolute; left: 168px; top: 87px;
           width: 408px; height:386px; background: url("../images/transpBlue_overlay.png"); }
        #overlay img { position:relative; left:200px; top:189px; }   
        </style>
        
        <!-- js scrolling -->
        <div id="tweets">
           <!-- Tweets will get loaded from jQuery -->
        </div>
        <div id="viewmore" style="background-color:gray; width:84%;pointer:cursor">
            <div style="text-align: center;padding-top: 10px;padding-bottom: 10px;pointer:cursor" onclick="return OnViewMore('<?php echo $loggedUserObj->userId; ?>','<?php echo $loggedUserObj->privacyType["Default_Setting"]; ?>',false,postTypeToRead.page,'<?php echo $arrPageDetail[0]["Comp_Page_ID"]; ?>');">
                View More >>
            </div>
           <!-- Tweets will get loaded from jQuery -->
        </div>
        <!--<div id="overlay">
           <img src="images/ajax-loader.gif" />
        </div>-->
        <!-- js scrolling -->
        
        <script type="text/javascript">
            // Set the size for each page to load
            requserid='<?php echo $loggedUserObj->userId; ?>';
            requserprivacysetting='<?php echo $loggedUserObj->privacyType["Default_Setting"]; ?>';
            
            // Set the size for each page to load
            
            var pageSize = 15;              
            // Username to load the timeline from
            var username = 'marcofolio';             
            // Variable for the current page
            var currentPage = 1;            
            // Loads the next tweets
            var loadTweets = function(lsttweet) {
               //getNewsFeeds('<?php echo $loggedUserObj->userId; ?>','0','<?php echo $loggedUserObj->privacyType["Default_Setting"]; ?>');
               OnViewMore('<?php echo $loggedUserObj->userId; ?>','<?php echo $loggedUserObj->privacyType["Default_Setting"]; ?>',true,postTypeToRead.page,'<?php echo $arrPageDetail[0]["Comp_Page_ID"]; ?>');
            };
            
            // First time, directly load the tweets
            loadTweets(0);
            /*
            // Append a scroll event handler to the container
            $(document).scroll(function() {
               // We check if we're at the bottom of the scrollcontainer
               var windowScrollHeight=parseInt($(window).scrollTop() + $(window).height());
               
               if(windowScrollHeight == $(document).height()) {
                   //alert("bottom!");
                   // getData();
               }
               else{
                    if(windowScrollHeight>(parseInt($(document).height())-300) ) {
                        //find last feed id read
                        var lastTweetRead= $("#tweets .feed:last-child").find(".lstfeedtime").val();
                        loadTweets(lastTweetRead);
                        currentPage++;
                        $("#overlay").fadeIn();
                    }
               }
               
               //if ($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {             
//                  // If we're at the bottom, show the overlay and retrieve the next page
//                  currentPage++;
//                  $("#overlay").fadeIn();
//                  loadTweets();
//               }
            });
            */      
        </script>
        
        
        
		</div> 
	   
	      
</div>

    </div>
    
    <div class="clearfix"></div>
    <!--=================Body Contain end=======================-->	
	
    </div>
    
    
    <div class="clearfix"></div>
      <?php include_once "common_divs_include.php"; ?>
    <?php include_once "includes/footer.php"; ?>
    
</div>
    <!--=================Footer end=======================-->
   
    <script>

        $( "#frmstupdt" ).submit(function( event ) {

          // Stop form from submitting normally

          event.preventDefault();

          // Get some values from elements on the page:

          ust("frmstupdt");

          /*

          var $form = $( this ),

            term = $form.find( "input[name='ajx_status_update']" ).val(),

            url = $form.attr( "action" );

         

          // Send the data using post

          var posting = $.post( url, { sStatus: term } );

          // Put the results in a div

          posting.done(function( data ) {

            if(document.getElementById("errconsole")){

                document.getElementById("errconsole").innerHTML=data;

            }

            //alert(data);

            //var content = $( data ).find( "#content" );

            //$( "#result" ).empty().append( content );

          });

          */

        });

        function updateStatus(){

            ust("frmstupdt");

        }

        function showEmotionsBox(){     
            
            if($("#status_emotions")){
                if($("#status_emotions").css("display")=="none"){
                    $("#status_emotions").show();
                    $("#emotionslist").hide();
                }
                else{
                    $("#status_emotions").hide();
                }
            }
            
            
        }
        function openEmotionCategoriesList(){
            if($("#emotionslist")){
                if($("#emotionslist").css("display")=="none"){
                    getEmotionsDropdown();
                    $("#emotionslist").show();
                }
                else{
                    $("#emotionslist").hide();
                }
            }
        }
    </script>
</body>
</html>
<script>
<?php
if(isset($msg_success) && $msg_success!="")
{
    ?>
    alertify.alert("<?php echo $msg_success; ?>");
    <?php
}

if(isset($msg_error) && $msg_error!="")
{
    ?>
    alertify.alert("<?php echo $msg_error; ?>");
    <?php
}
?>
</script>
